<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      // 使用 WebRTC API 获取本机网络信息
      function getInternalIP() {
        return new Promise((resolve, reject) => {
          const { RTCPeerConnection, RTCSessionDescription } = window
          const pc = new RTCPeerConnection({ iceServers: [] })
          pc.createDataChannel('')
          pc.createOffer()
            .then((offer) => {
              const desc = new RTCSessionDescription(offer)
              pc.setLocalDescription(desc)
            })
            .catch(reject)

          pc.onicecandidate = (e) => {
            if (e.candidate) {
              const match = e.candidate.candidate.match(/(192\.168\.\d+\.\d+)/)
              if (match) {
                resolve(match[1])
              }
            } else {
              reject(new Error('Failed to get internal IP'))
            }
          }
        })
      }

      // 使用示例
      getInternalIP()
        .then((ip) => {
          console.log('Internal IP:', ip)
        })
        .catch((error) => {
          console.error(error)
        })
    </script>
  </body>
</html>
